import {defineStore,} from 'pinia'
import router from "@/routers/index.js";

export const useUserStore = defineStore('user', {
    state: () => ({
        token: '',
        userInfo: null
    }),
    getters: {
        getToken(state) {
            return state.token
        },
        getUserInfo(state) {
            return state.userInfo
        }
    },
    actions: {
        setToken(token) {
            this.token = token
        },
        removeToken() {
            this.token = ''
        },
        setUserInfo(userInfo) {
            this.userInfo = userInfo
        },
        removeUser() {
            this.userInfo = {}
        },
        reloadLogin() {
            this.removeToken()
            this.removeUser()
            router.replace('/login')
        }

    },
    persist: true
})